// ml:run = $bin < input
#include <iostream>

int const opt[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
int const maxn = 50;
int a[maxn][maxn];
int n, m;

bool inrange(int x, int y)
{
    return (1 <= x && x <= n) && (1 <= y && y <= m);
}

bool judge()
{
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            for (int t = 0; t < 4; t++) {
                int x = i + opt[t][0];
                int y = j + opt[t][1];
                if (!inrange(x, y)) continue;
                if (a[i][j] == a[x][y]) return true;
            }
        }
    }
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++) {
            if (a[i][1] == a[j][1]) return true;
            if (a[i][m] == a[j][m]) return true;
        }
    for (int i = 1; i <= m; i++)
        for (int j = i + 1; j <= m; j++) {
            if (a[1][i] == a[1][j]) return true;
            if (a[n][i] == a[n][j]) return true;
        }
    return false;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    int T; std::cin >> T;
    for (int ti = 1; ti <= T; ti++) {
        std::cout << "Case #" << ti << ": ";
        std::cin >> n >> m;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++) std::cin >> a[i][j];
        if (judge()) std::cout << "Yes\n";
        else std::cout << "No\n";
    }
}

